package com.sevenyear.excelanalyze.listener.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.sevenyear.excelanalyze.entity.PartitionBaseInfo;
import com.sevenyear.excelanalyze.entity.param.entityParam.PartitionBaseInfoParam;
import com.sevenyear.excelanalyze.service.PartitionBaseInfoService;
import org.springframework.beans.BeanUtils;

/**
 * @author ：SevenYear
 * @description：TODO
 * @date ：2021/8/20 22:10
 */
public class PartitionBaseInfoListener extends AnalysisEventListener<PartitionBaseInfoParam> {

    private PartitionBaseInfoService partitionBaseInfoService;

    public PartitionBaseInfoListener() {
    }

    public PartitionBaseInfoListener(PartitionBaseInfoService partitionBaseInfoService) {
        this.partitionBaseInfoService = partitionBaseInfoService;
    }


    @Override
    public void invoke(PartitionBaseInfoParam partitionBaseInfoParam, AnalysisContext analysisContext) {
        PartitionBaseInfo partitionBaseInfo = new PartitionBaseInfo();
        BeanUtils.copyProperties(partitionBaseInfoParam,partitionBaseInfo);
        System.out.println("excelPartitionInfoData:::"+ partitionBaseInfoParam.toString());
        System.out.println("partitionBaseInfo:::"+partitionBaseInfo.toString());
        System.out.println();
        partitionBaseInfoService.save(partitionBaseInfo);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
